package com.feng.controller;

import com.feng.annotation.SystemLog;
import com.feng.domain.ResponseResult;
import com.feng.domain.dto.TagListDto;
import com.feng.domain.dto.UpdateTagDto;
import com.feng.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/content/tag")
public class TagController {

    @Autowired
    private TagService tagService;

    @PreAuthorize("@ps.hasPermission('content/tag/index')")
    @GetMapping("/list")
    public ResponseResult list(Integer pageNum, Integer pageSize, TagListDto tagListDto){
        return tagService.tagList(pageNum, pageSize, tagListDto);
    }

    @PreAuthorize("@ps.hasPermission('content/tag/index')")
    @SystemLog(businessName = "添加标签")
    @PostMapping
    public ResponseResult addTag(@RequestBody TagListDto tagListDto){
        return tagService.addTag(tagListDto);
    }

    @PreAuthorize("@ps.hasPermission('content/tag/index')")
    @SystemLog(businessName = "删除标签")
    @DeleteMapping("/{id}")
    public ResponseResult delTag(@PathVariable("id") List<Long> idList){
        return tagService.delTag(idList);
    }

    @PreAuthorize("@ps.hasPermission('content/tag/index')")
    @GetMapping("/{id}")
    public ResponseResult getTag(@PathVariable("id") Long id){
        return tagService.getTag(id);
    }

    @PreAuthorize("@ps.hasPermission('content/tag/index')")
    @PutMapping
    public ResponseResult updateTag(@RequestBody UpdateTagDto tagDto){
        return tagService.updateTag(tagDto);
    }

    @PreAuthorize("@ps.hasPermission('content/article/write/index')")
    @GetMapping("/listAllTag")
    public ResponseResult listAllTag(){
        return tagService.listAllTag();
    }
}
